package org.hnxxxy.ebms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import org.hnxxxy.ebms.common.Result;
import org.hnxxxy.ebms.pojo.RecruitStu;
import org.hnxxxy.ebms.service.RecruitStuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author WANGWEI
 * @since 2021-06-10
 */
@RestController
@RequestMapping("/recruit-stu")
public class RecruitStuController {

    @Autowired
    public RecruitStuService recruitStuService;

    @PostMapping("/add")
    @ApiOperation(value = "增加招生学生名单")
    public Result<String> addRecruitStu(@RequestBody RecruitStu recruitStu){
        return recruitStuService.add(recruitStu);
    }

    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "删除招生学生名单")
    public Result<String> delRecruitStu(@PathVariable("id") Integer id){
        if (recruitStuService.removeById(id)){
            return Result.success(200,"删除成功");
        }
        return Result.fail("删除失败");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改招生学生名单")
    public Result<String> updateRecruitStu(@RequestBody RecruitStu recruitStu){
        if (recruitStuService.updateById(recruitStu)){
            return Result.success(200,"修改成功");
        }
        return Result.fail("删除失败");
    }

    @GetMapping("/get/{page}")
    @ApiOperation(value = "查询所属地区招生学生")
    public Result<IPage<RecruitStu>> getRecStus(@PathVariable("page") int page){
        return recruitStuService.getRecStus(page);
    }

    @GetMapping("/getName/{name}/{page}")
    @ApiOperation(value = "根据姓名查询")
    public Result<IPage<RecruitStu>> getRecStusByName(@PathVariable("name") String name,@PathVariable("page") int page){
        return recruitStuService.getRecStusByName(name,page);
    }

}
